package com.kcsoft.welcome.controller;

import com.kcsoft.welcome.pojo.PageBean;
import com.kcsoft.welcome.pojo.Prize;
import com.kcsoft.welcome.pojo.Result;
import com.kcsoft.welcome.service.PrizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/prize")
public class PrizeController {

    @Autowired
    PrizeService prizeService;

    @PostMapping("/upload")
    public Result upload(@RequestParam("file")MultipartFile file) {
        if (file.isEmpty()) {
            return Result.error("文件为空");
        }
        prizeService.upload(file);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<PageBean<Prize>> list(Integer pageNum, Integer pageSize) {
        PageBean<Prize> pb = prizeService.list(pageNum, pageSize);
        return Result.success(pb);
    }

    @PostMapping("update")
    public Result update(@RequestBody Prize prize) {
        prizeService.update(prize);
        return Result.success();
    }

    @PostMapping("/delete")
    public Result delete(Integer id) {
        prizeService.delete(id);
        return Result.success();
    }

}
